//
//  ForgetViewController.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/18.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class ForgetViewController: UITableViewController,ForgetCellDelegate {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //设置样式
        setStyle()
        
        self.navigationItem.title = "忘记密码"
    }
}

// MARK:- 表格代理和方法
extension ForgetViewController {
    // MARK: - Table view data source
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellID") as? ForgetCell
        
        if cell == nil {
            //去除分割线
            tableView.separatorStyle = UITableViewCellSeparatorStyle.none
            cell = ForgetCell(style: .default, reuseIdentifier: "cellID")
            cell?.delegate = self
            
        }
        //按section进行控件隐藏
        cell?.imgView.image = UIImage.init(named: "ico")
        //控制每行textfield控件的隐藏顺序
        if indexPath.section == 0 && indexPath.row == 0 {
            cell?.tfNum.isHidden = false
        } else {
            cell?.tfNum.isHidden = true
        }
        
        if indexPath.section == 0 && indexPath.row == 1 {
            cell?.yzmBtn.isHidden = false
            
            cell?.tfAuto.isHidden = false
        } else {
            cell?.tfAuto.isHidden = true
            cell?.line.isHidden = true
            cell?.yzmBtn.isHidden = true
            
        }
        
        if indexPath.section == 0 && indexPath.row == 2 {
            
            cell?.tfPass.isHidden = false
        } else {
            
            cell?.tfPass.isHidden = true
        }
        
        if indexPath.section == 0 && indexPath.row == 3 {
            cell?.tfConfirmPass.isHidden = false
        } else {
            cell?.tfConfirmPass.isHidden = true
        }
        
        if indexPath.section == 1 {
            cell?.backgroundColor = UIColor.clear
            cell?.imgView.isHidden = true
            cell?.btn.isHidden = false
            cell?.line.isHidden = true
        } else {
            cell?.imgView.isHidden = false
            cell?.btn.isHidden = true
            cell?.line.isHidden = false
        }
        
        return cell!
        
        
        
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 2
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        switch section {
        case 0:
            return 4
        default:
            return 1
        }
        
        
    }
    
    //设置section 间距
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 1
    }
    
    //设置行高
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch indexPath.row {
        case 4:
            return 30
        default:
            return 45
        }
        
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("点击了 ",indexPath.row)
    }
    
    override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        if indexPath.section == 0 && indexPath.row == 4 {
            
        }
    }
}

//设置表格样式
extension ForgetViewController {
    func setStyle() -> Void {
        //设置样式组
        tableView.tableFooterView = UIView()
        tableView.backgroundColor = UIColor.gray
        //去除分割线
        
        tableView = UITableView(frame: self.view.bounds, style: .grouped)
    }
}


extension ForgetViewController {
    func choosePic(_com: (String?)) {
        print(_com as Any)
    }
}
